<template>
  <div class="home" v-loading="isLoading">
    <div class="main">
      <p style="font-size: 20px; font-weight: 700; color: #000">慢病随访汇总</p>
      <!-- <div style="margin-top: 5px">
          <span style="font-weight: 700;">公卫人群：</span>
          <el-button
            :type="item.txt == isNowBtn ? 'primary' : ''"
            :style="item.txt == isNowBtn ? 'font-weight:700;' : ''"
            size="small"
            v-for="item in btn_list"
            :key="item.index"
            @click="btn_flag_click(item)"
            class="btn_sty"
            >{{ item.txt }}</el-button
          >
        </div> -->
      <div style="margin-top: 5px">
        <span style="font-weight: 700">慢病人群：</span>
        <el-button
          :type="item.txt == isNowBtn ? 'primary' : ''"
          :style="item.txt == isNowBtn ? 'font-weight:700;' : ''"
          size="small"
          v-for="item in btn_list2"
          :key="item.index"
          @click="btn_flag_click2(item)"
          class="btn_sty"
          >{{ item.txt }}</el-button
        >
        <span style="font-weight: 700; display: inline-block; margin-left: 20px"
          >查询时间：</span
        >
        <el-radio-group
          v-model="formLabelAlign.filter.timeType"
          @change="get_list"
          size="small"
        >
          <el-radio-button label="-1">全部</el-radio-button>
          <el-radio-button label="0">已过期</el-radio-button>
          <el-radio-button label="1">未过期</el-radio-button>
        </el-radio-group>
      </div>

      <ul style="padding: 15px" v-if="!isLoading">
        <li
          class="item_user"
          v-for="item in tableData"
          :key="item.id"
          @click="to_user_info(item.BaseInfo.IdCard)"
        >
          <div class="l">
            <span
              style="
                color: #1890ff;
                font-weight: 700;
                font-size: 18px;
                vertical-align: middle;
              "
              >{{ item.BaseInfo.ResidentName }}</span
            >
            <span class="tip2">{{ isNowBtn }}</span>
            <p style="margin-top: 10px">
              证件号码：<span style="font-weight: 700; color: #000">{{
                item.BaseInfo.IdCard
              }}</span>
            </p>
            <p>
              下次随访日期：{{ item.NextDate | time }}
              <span class="tip" v-if="item.TotalDays > 0"
                >还剩：{{ parseInt(item.TotalDays) }}天</span
              >
              <span class="tip2" v-if="item.TotalDays < 0"
                >已过期：{{ parseInt(item.TotalDays) }}天</span
              >
            </p>
          </div>
          <div class="r">
            <el-button
              style="
                font-size: 14px;
                background-color: #fff;
                color: rgb(47, 159, 254);
              "
              type="primary"
              size="small"
              plain
              >患者健康档案</el-button
            >
          </div>
        </li>
      </ul>
      <div style="text-align: right; margin-top: 20px">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="formLabelAlign.page"
          :page-size="formLabelAlign.size"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 弹层开始 -->
    <el-dialog
      title="健康体检表"
      :visible.sync="dialogVisible"
      width="96%"
      style="margin-top: -10vh"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <div style="height: 65vh; overflow: auto">
        <jktjb></jktjb>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >保 存</el-button
        >
      </span>
    </el-dialog>
    <!-- 弹层结束 -->
  </div>
</template>
  
  <script>
import jktjb from "@/views/dialog_info/jktjb.vue"; // 健康体检表
export default {
  components: {
    jktjb,
  },
  data() {
    return {
      btn_list: [
        { index: 1, txt: "普通居民" },
        { index: 2, txt: "0 ~ 6 岁儿童" },
        { index: 4, txt: "孕产妇" },
        { index: 8, txt: "65岁及以上老人" },
        { index: 16, txt: "高血压患者" },
        { index: 32, txt: "2型糖尿病患者" },
        { index: 64, txt: "严重精神障碍患者" },
        { index: 128, txt: "肺结核患者" },
      ],
      btn_list2: [
        // { index: 1, txt: "脑血管病" },
        //   { index: 2, txt: "冠心病" },
        //   { index: 3, txt: "慢阻肺" },
        // { index: 4, txt: "类风湿关节炎" },
        // { index: 5, txt: "骨关节炎" },
        // { index: 6, txt: "重型老年慢性支气管炎" },
        { index: 7, txt: "高血压" },
        { index: 8, txt: "糖尿病" },
        //   { index: 9, txt: "脑卒中" },
        // { index: 10, txt: "肿瘤" },
        // { index: 11, txt: "其他" },
      ],
      isNowBtn: "高血压",
      dialogVisible: false,
      tableData: [],
      isLoading: false,
      formLabelAlign: {
        currentPage: "1",
        pageSize: "10",
        filter: {
          type: "高血压",
          timeType: "-1",
        },
      },
      isBtn_id: 1,
      isBtn_id2: null,
      total: 1,
    };
  },
  mounted() {
    this.get_list();
  },
  methods: {
    btn_flag_click(val) {
      this.isNowBtn = val.txt;
      this.isBtn_id = val.index;
      this.isBtn_id2 = null;
      this.get_list();
    },
    btn_flag_click2(val) {
      this.isNowBtn = val.txt;
      this.isBtn_id2 = val.index;
      this.isBtn_id = null;
      this.get_list();
    },
    goto_charteDa() {
      this.$router.push('/carte_da')
      // window.open("/#/carte_da");
    },
    handleClose() {
      this.dialogVisible = false;
    },
    goto_open() {
      this.dialogVisible = true;
    },
    to_user_info(idCard) {
      if (this.isBtn_id) {
        this.$router.push("/user_info?idCard=" + idCard);
      } else {
        this.$router.push("/user_info_mb?idCard=" + idCard);
      }
    },
    get_list() {
      this.isLoading = true;
      var body = this.formLabelAlign;
      // body.groupType = this.isBtn_id
      // body.chronicType = this.isBtn_id2
      this.$post(
        "http://192.168.0.13:8080/api/PatBaseInfo/GetPendingVisit",
        body
      ).then((res) => {
        this.total = res.Data.Total;
        this.tableData = res.Data.PageList;
        this.isLoading = false;
      });
    },
    handleCurrentChange(val) {
      this.formLabelAlign.currentPage = val;
      this.get_list();
    },
  },
  filters: {
    groupType_to(val) {
      var array = val.split(",");
      var str = [
        {
          id: 1,
          name: "普",
        },
        {
          id: 2,
          name: "儿",
        },
        {
          id: 4,
          name: "孕",
        },
        {
          id: 8,
          name: "老",
        },
        {
          id: 16,
          name: "高",
        },
        {
          id: 32,
          name: "糖",
        },
        {
          id: 64,
          name: "精",
        },
        {
          id: 128,
          name: "肺",
        },
      ];
      var newArry = [];
      for (var i in array) {
        for (var j in str) {
          if (array[i] == str[j].id) {
            newArry.push(str[j].name);
          }
        }
      }
      return newArry.toString();
    },
    chronicType_to(val) {
      if (val.split(",")) {
        var array = val.split(",");
      } else {
        var array = [val];
      }
      var str = [
        {
          id: 2,
          name: "冠心病",
        },
        {
          id: 3,
          name: "慢阻肺",
        },
        {
          id: 7,
          name: "高血压",
        },
        {
          id: 8,
          name: "糖尿病",
        },
        {
          id: 9,
          name: "脑卒中",
        },
      ];
      var newArry = [];
      for (var i in array) {
        for (var j in str) {
          if (array[i] == str[j].id) {
            newArry.push(str[j].name);
          }
        }
      }
      return newArry.toString();
    },
    time(val) {
      if (val == null || val == "") {
        return "";
      } else {
        let d = new Date(val); // val 为表格内取到的后台时间
        let month =
          d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
        let day = d.getDate() < 10 ? "0" + d.getDate() : d.getDate();
        let hours = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
        let min = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
        let sec = d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds();
        let times = d.getFullYear() + "-" + month + "-" + day;
        return times;
      }
    },
  },
};
</script>
  
  <style scoped lang="scss">
.home {
  .top {
    padding: 20px;
    background-color: #fff;
    border: 1px solid #ccc;
    .user_name {
      display: inline-block;
      font-weight: 700;
      font-size: 20px;
      color: #000;
      padding: 0 20px;
      margin-right: 50px;
    }
  }
  .li_item {
    display: inline-block;
    background: url(https://yngw-phlnewadmin.yiboshi.com/static/1686134276923/img/indexStatisBg.38834396.png)
      no-repeat;
    background-color: #f8fafc;
    width: 15.5%;
    margin-right: 1.4%;
    padding: 12px;
    border-radius: 4px;
  }
  .main {
    margin: 10px;
    padding: 25px 15px;
    background-color: #fff;
    border-radius: 5px;
    border: 1px solid #ccc;
    .btn_sty {
      font-size: 18px;
    }
    .item_user {
      padding: 15px;
      border: 1px solid #ccc;
      background-color: rgb(252, 252, 252);
      border-radius: 5px;
      margin-bottom: 8px;
      .l {
        display: inline-block;
        width: 50%;
        vertical-align: middle;
        .tip {
          display: inline-block;
          padding: 5px 8px;
          color: #fa8c16;
          background: #fff7e6;
          border: 1px solid #ffd591;
          margin-left: 10px;
          font-size: 12px;
          vertical-align: middle;
        }
        .tip2 {
          display: inline-block;
          padding: 5px 8px;
          color: #fa1616;
          background: #ffe6e6;
          border: 1px solid #ff9191;
          margin-left: 10px;
          font-size: 12px;
          vertical-align: middle;
        }
      }
      .r {
        display: inline-block;
        width: 50%;
        text-align: right;
        vertical-align: middle;
      }
    }
  }
}
</style>